// types.h

#ifndef _KS_INC_TYPES_H_
#define _KS_INC_TYPES_H_

#ifdef __cplusplus
	#define KS_DECLS_BEGIN	extern "C" {
	#define KS_DECLS_END	}
#else
	#define KS_DECLS_BEGIN
	#define KS_DECLS_END
#endif

#ifdef _DEBUG
	#define KS_DEBUG
#endif

// inttype
// 
#ifdef _MSC_VER
	#include <stdint.h>

	#define PRId8		"d"
	#define PRId16		"d"
	#define PRId32		"d"
	#define PRId64		"I64d"

	#define PRIu8		"u"
	#define PRIu16		"u"
	#define PRIu32		"u"
	#define PRIu64		"I64u"

	#if (_MSC_VER < 1800)
		#define strtoll		_strtoi64
		#define strtoull	_strtoui64
		#define strtold		(long double)strtod
		#define strtof		(float)strtod
	#endif

	#ifndef snprintf
		#define snprintf	_snprintf
		#define vsnprintf	_vsnprintf
	#endif

#else
	#ifndef __STDC_FORMAT_MACROS
		#define __STDC_FORMAT_MACROS
	#endif
	#include <inttypes.h>
	#include <stdint.h>
#endif

#define PRIld32		"ld"
#define PRIlu32		"lu"

#define PRId64_F 	"%" PRId64
#define PRIu64_F 	"%" PRIu64

// BOOL
// 
typedef int		BOOL;

#ifndef TRUE
	#define TRUE	1
#endif

#ifndef FALSE
	#define FALSE	0
#endif

// C inline
// 
#ifndef  __cplusplus
	#ifdef _MSC_VER
		#ifdef inline
			#undef inline
		#endif
		#define inline __forceinline
	#endif
#endif

// member offset
// 
#ifdef offsetof
	#define ks_offset_of	offsetof
#else
	#define ks_offset_of(type, member)			( (intptr_t)(  &((type *)0)->member  ) )
#endif

#define	ks_member_offset(ptr, type, member)	( (type *)(  (char *)(ptr) - ks_offset_of(type, member)  ) )

#ifdef _MSC_VER
	#if _MSC_VER >= 1400	// vc8
		#define KS_HAVE_ISO_VARARGS 1
	#endif
#else
	#define KS_HAVE_ISO_VARARGS 1
#endif

#ifdef _MSC_VER
	#pragma warning(disable : 4200)		// nonstandard extension used : zero-sized array in struct/union
	#pragma warning(disable: 4996)		// VC++ depart functions warning
#endif

#endif//_KS_INC_TYPES_H_

